package com.zy.configs;

import com.zy.myLoadBalancers.MyOnlyOneLoadBalancer;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.loadbalancer.core.ReactorLoadBalancer;
import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier;
import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;

/**
 * @program: shopping153_cloud
 * @description:
 * @author: zy
 * @create: 2025-08-22 14:56
 */
public class MyOnlyOneLoadBalancerConfig {

    @Bean
    public ReactorLoadBalancer<ServiceInstance> rlb(Environment environment,
                                                    LoadBalancerClientFactory loadBalancerClientFactory) {
        String name = environment.getProperty(LoadBalancerClientFactory.PROPERTY_NAME);
        return new MyOnlyOneLoadBalancer(  loadBalancerClientFactory.getLazyProvider(name, ServiceInstanceListSupplier.class)  , name);
    }
}
